using System.Collections.Generic;
using System.Text;
using System;
using NHibernate;
using NHibernate.Cfg;
using JVLMRP;
namespace JVLMRP 
{
    class MRPUserMenuService 
    {
        ISession session;

        public MRPUserMenuService(ISession session)
        {
            this.session = session;
        }
        public MRPUserMenuService( )
        {
            this.session = SessionFactory.GetNewSession();
        }
        public void InsertMrpusermenu(MRPUserMenu mrpusermenuX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Save(mrpusermenuX);
            tx.Commit();
        }

        public void UpdateMrpusermenu(MRPUserMenu mrpusermenuX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Update(mrpusermenuX);
            tx.Commit();
        }

        public void DeleteMrpusermenu(MRPUserMenu mrpusermenuX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Delete(mrpusermenuX);
            tx.Commit();
        }

        public IList<MRPUserMenu> GetAllMrpusermenu(Boolean evict)
        {
            IQuery query = session.CreateQuery("select from MRPUserMenu");
            IList<MRPUserMenu> list = query.List<MRPUserMenu>();
            if (evict)
            {
                foreach (MRPUserMenu s in list)
                {
                session.Evict(s);
                }
            }
            return list;
        }

        public MRPUserMenu GetAllMrpusermenuByID(String id,Boolean evict)
        {
            IQuery query = session.CreateQuery("select c from MRPUserMenu as c where c.Usermenuid= :x");
            query.SetString("x", id);
            MRPUserMenu s = (MRPUserMenu)query.UniqueResult();
            if (evict)
            {
                session.Evict(s);
            }
            return s;
        }

        public IList<MRPUserMenu> GetMrpusermenuByQuery(IQuery query,Boolean evict)
        {
            IList<MRPUserMenu> list = query.List<MRPUserMenu>();
            if (evict)
            {
                foreach (MRPUserMenu s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }
    }
}
